package com.lycx.businessmanager.controller.systemManager;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lycx.businessmanager.controller.BaseController;
import com.lycx.businessmanager.model.User;
import com.lycx.businessmanager.service.IUserService;
import com.lycx.businessmanager.util.MyUtils;
import com.lycx.businessmanager.util.SysContext;

/**
 * 人员controller
 * 
 * @author lambert
 * 
 */

@Controller
@RequestMapping("/user")
public class UserController extends BaseController{
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(UserController.class);
	private IUserService userService;

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}

	@RequestMapping(value = "/list")
	public ModelAndView list(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("/system/user/list");
		return mv;
	}
	
	@RequestMapping(value = "/getList",method = RequestMethod.POST)
	@ResponseBody
	public List<User> getList(User user){
		List<User> userList = null;
		userList = userService.select(user);
        return userList;
	}

	
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public String add(User user){
		String result = null;
		if(user!=null){
	        result = userService.add(user);
		}
        return result;
	}
	
	@RequestMapping(value = "/del",method = RequestMethod.POST)
	@ResponseBody
	public String del(int ids[]){
		String result = null;
		result = userService.del(ids);
		return result;
	}
	
	@RequestMapping(value = "/mod",method = RequestMethod.POST)
	@ResponseBody
	public String mod(User user){
		String result = null;
		if(user!=null){
			result = userService.mod(user);
		}
		return result;
	}
	
	@RequestMapping(value = "/reset",method = RequestMethod.POST)
	@ResponseBody
	public String reset(User user){
		String result = null;
		if(user!=null){
			user.setPassword(MyUtils.encryptMD5(SysContext.DEFAULT_PASSWORD));
			result = userService.mod(user);
		}
		return result;
	}
	
}
